import { IColumnProps } from "devextreme-react/data-grid"
import { consts } from "../../../consts";
/**
 * 风险系统表
 */

export const riskCoefficientDataSource = [
    { acceptableDevSize: 0, percent1: 4.61, percent5: 3, percent10: 2.31, percent15: 1.9, percent20: 1.61, percent25: 1.39, percent30: 1.21, percent37: 1, percent50: 0.7 },
    { acceptableDevSize: 1, percent1: 6.64, percent5: 4.75, percent10: 3.89, percent15: 3.38, percent20: 3, percent25: 2.7, percent30: 2.44, percent37: 2.14, percent50: 1.68 },
    { acceptableDevSize: 2, percent1: 8.41, percent5: 6.3, percent10: 5.33, percent15: 4.72, percent20: 4.28, percent25: 3.93, percent30: 3.62, percent37: 3.25, percent50: 2.68 },
    { acceptableDevSize: 3, percent1: 10.05, percent5: 7.76, percent10: 6.69, percent15: 6.02, percent20: 5.52, percent25: 5.11, percent30: 4.77, percent37: 4.34, percent50: 3.68 },
    { acceptableDevSize: 4, percent1: 11.61, percent5: 9.16, percent10: 8, percent15: 7.27, percent20: 6.73, percent25: 6.28, percent30: 5.9, percent37: 5.43, percent50: 4.68 },
    { acceptableDevSize: 5, percent1: 13.11, percent5: 10.52, percent10: 9.28, percent15: 8.5, percent20: 7.91, percent25: 7.43, percent30: 7.01, percent37: 6.49, percent50: 5.68 },
    { acceptableDevSize: 6, percent1: 14.57, percent5: 11.85, percent10: 10.54, percent15: 9.71, percent20: 9.08, percent25: 8.56, percent30: 8.12, percent37: 7.56, percent50: 6.67 },
    { acceptableDevSize: 7, percent1: 16, percent5: 13.15, percent10: 11.78, percent15: 10.9, percent20: 10.24, percent25: 9.69, percent30: 9.21, percent37: 8.63, percent50: 7.67 },
    { acceptableDevSize: 8, percent1: 17.41, percent5: 14.44, percent10: 13, percent15: 12.08, percent20: 11.38, percent25: 10.81, percent30: 10.31, percent37: 9.68, percent50: 8.67 },
    { acceptableDevSize: 9, percent1: 18.79, percent5: 15.71, percent10: 14.21, percent15: 13.25, percent20: 12.52, percent25: 11.92, percent30: 11.39, percent37: 10.74, percent50: 9.67 },
    { acceptableDevSize: 10, percent1: 20.15, percent5: 16.97, percent10: 15.41, percent15: 14.42, percent20: 13.66, percent25: 13.02, percent30: 12.47, percent37: 11.79, percent50: 10.67 },
    { acceptableDevSize: 11, percent1: 21.49, percent5: 18.21, percent10: 16.6, percent15: 15.57, percent20: 14.78, percent25: 14.13, percent30: 13.55, percent37: 12.84, percent50: 11.67 },
    { acceptableDevSize: 12, percent1: 22.83, percent5: 19.45, percent10: 17.79, percent15: 16.72, percent20: 15.9, percent25: 15.22, percent30: 14.63, percent37: 13.89, percent50: 12.67 },
    { acceptableDevSize: 13, percent1: 24.14, percent5: 20.67, percent10: 18.96, percent15: 17.86, percent20: 17.02, percent25: 16.32, percent30: 15.7, percent37: 14.93, percent50: 13.67 },
    { acceptableDevSize: 14, percent1: 25.45, percent5: 21.89, percent10: 20.13, percent15: 19, percent20: 18.13, percent25: 17.4, percent30: 16.77, percent37: 15.97, percent50: 14.67 },
    { acceptableDevSize: 15, percent1: 26.75, percent5: 23.1, percent10: 21.3, percent15: 20.13, percent20: 19.24, percent25: 18.49, percent30: 17.84, percent37: 17.02, percent50: 15.67 },
    { acceptableDevSize: 16, percent1: 28.03, percent5: 24.31, percent10: 22.46, percent15: 21.26, percent20: 20.34, percent25: 19.58, percent30: 18.9, percent37: 18.06, percent50: 16.67 },
    { acceptableDevSize: 17, percent1: 29.31, percent5: 25.5, percent10: 23.61, percent15: 22.39, percent20: 21.44, percent25: 20.66, percent30: 19.97, percent37: 19.1, percent50: 17.67 },
    { acceptableDevSize: 18, percent1: 30.59, percent5: 26.7, percent10: 24.76, percent15: 23.51, percent20: 22.54, percent25: 21.74, percent30: 21.03, percent37: 20.14, percent50: 18.67 },
    { acceptableDevSize: 19, percent1: 31.85, percent5: 27.88, percent10: 25.91, percent15: 24.63, percent20: 23.64, percent25: 22.81, percent30: 22.09, percent37: 21.18, percent50: 19.67 },
    { acceptableDevSize: 20, percent1: 33.11, percent5: 29.07, percent10: 27.05, percent15: 25.74, percent20: 24.73, percent25: 23.89, percent30: 23.15, percent37: 22.22, percent50: 20.67 },

]
function getHeaderTemplate(mainTitle: string, subTitle: string) {
    return `<div style="font-weight: normal ">${mainTitle}<div style="font-size: 14 ">${subTitle}</div></div>`
}

export function getRiskCoefficientColumns(): IColumnProps[] {
    return [
        {
            dataField: "acceptableDevSize",
            alignment: 'center',
            caption: '可接受的偏差数量',
            allowFiltering: false,
            allowSorting: false,
            width: 150,
        },
        {
            caption: '可接受风险水平',
            columns: [
                {
                    caption: '1%',
                    dataField: "percent1",
                    alignment: 'center',
                    allowFiltering: false,
                    allowSorting: false,
                    width: 88,
                    format: consts.numberFormat,
                },
                {
                    caption: '5%',
                    dataField: "percent5",
                    alignment: 'center',
                    allowFiltering: false,
                    allowSorting: false,
                    width: 88,
                    format: consts.numberFormat,
                },
                {
                    caption: '10%',
                    dataField: "percent10",
                    alignment: 'center',
                    allowFiltering: false,
                    allowSorting: false,
                    width: 88,
                    format: consts.numberFormat,
                },
                {
                    caption: '15%',
                    dataField: "percent15",
                    alignment: 'center',
                    allowFiltering: false,
                    allowSorting: false,
                    width: 88,
                    format: consts.numberFormat,
                },
                {
                    caption: '20%',
                    dataField: "percent20",
                    alignment: 'center',
                    allowFiltering: false,
                    allowSorting: false,
                    width: 88,
                    format: consts.numberFormat,
                },
                {
                    caption: '25%',
                    dataField: "percent25",
                    alignment: 'center',
                    allowFiltering: false,
                    allowSorting: false,
                    width: 88,
                    format: consts.numberFormat,
                },
                {
                    caption: '30%',
                    dataField: "percent30",
                    alignment: 'center',
                    allowFiltering: false,
                    allowSorting: false,
                    width: 88,
                    format: consts.numberFormat,
                },
                {
                    caption: '37%',
                    dataField: "percent37",
                    alignment: 'center',
                    allowFiltering: false,
                    allowSorting: false,
                    width: 88,
                    format: consts.numberFormat,
                },
                {
                    caption: '50%',
                    dataField: "percent50",
                    alignment: 'center',
                    allowFiltering: false,
                    allowSorting: false,
                    width: 88,
                    format: consts.numberFormat,
                },


            ]
        }
    ]
}
export const riskCoefficientColumns = getRiskCoefficientColumns()
//可接受风险水平 数组
export const acceptableRiskArray = riskCoefficientColumns.find(item => item.columns)?.
    columns?.filter((item: IColumnProps) => item.dataField.startsWith('percent')).
    map((item: IColumnProps) => ({
        value: item.caption,
        text: item.caption
    }));
// 可接受的偏差数 数组
export const acceptableDevArray = riskCoefficientDataSource.map(item => ({
    value: item.acceptableDevSize,
    text: item.acceptableDevSize
}))

/**
 * 获取风险系统
 * @param majorMisstatementRisk 
 * @param otherSubstantiveRisk 
 */
export function getRiskCoefficient(acceptableRisk: string, acceptableDevSize: number): number {
    let colName = 'percent' + acceptableRisk.replace('%', '')
    const riskCoefficient: any = riskCoefficientDataSource.find(item => item.acceptableDevSize == acceptableDevSize);
    if (riskCoefficient) {
        return Number(riskCoefficient[colName])
    }
    return 0;
}